package org.grow.jpadsl.controller;

import com.querydsl.core.QueryResults;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.grow.jpadsl.dao.StudentScoreJpa;
import org.grow.jpadsl.entity.QStudentScore;
import org.grow.jpadsl.entity.StudentScore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 21-5-30
 */

@RestController
public class StudentScoreController {

    @GetMapping("/testMvc")
    private LocalDateTime testMvc(){
        return LocalDateTime.now();
    }

    @Autowired
    private JPAQueryFactory jpaQueryFactory;

    QStudentScore s = QStudentScore.studentScore;
    @PostMapping("/studentScores")
    public List<StudentScore> findAll(@RequestParam Integer pageNum,
                                       @RequestParam Integer pageSize){
        Integer pageStart = (pageNum-1)* pageSize;
        List<StudentScore> fetch = jpaQueryFactory.selectFrom(s).where(s.name.like("李%"))
                .orderBy(s.onlineScore.desc())
               .offset(pageStart).limit(pageSize).fetch();
        return fetch;
    }


}
